package com.xw.db137.service.impl;

import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.xw.db137.entity.Rolemenu;
import com.xw.db137.mapper.RolemenuMapper;
import com.xw.db137.service.RolemenuService;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
/**
  * @Author: xw
  * @CreateTime: 2024/12/24
  * @Description: 用户
  * @Version: 1.0
  */
@Service
public class RolemenuServiceImpl extends ServiceImpl<RolemenuMapper, Rolemenu> implements RolemenuService {

    @Override
    public boolean updateRoleMenuId(int roleid, List<Integer> listMenu) {
        //1、根据角色id删除这个角色菜单
        UpdateWrapper<Rolemenu> rolemenuUpdateWrapper = new UpdateWrapper<>();
        rolemenuUpdateWrapper.eq("roleid", roleid);
        this.baseMapper.delete(rolemenuUpdateWrapper);
        //2、根据角色id增加对应的菜单
        for (Integer menu : listMenu) {
            Rolemenu rolemenu = new Rolemenu();
            rolemenu.setRoleid(roleid);
            rolemenu.setMenuid(menu);
            this.baseMapper.insert(rolemenu);
        }
        return false;
    }
}
